/*
 * Copyright 2017 JessYan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cj.mobile.iabp.mvp.ui.holder;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ConvertUtils;
import com.cj.mobile.iabp.R;
import com.cj.mobile.iabp.app.utils.CommonUtils;
import com.cj.mobile.iabp.mvp.model.entity.PatientInfo;
import com.jess.arms.base.BaseHolder;
import com.jess.arms.base.DefaultAdapter;

import butterknife.BindView;

/**
 * ================================================
 * 展示 {@link BaseHolder} 的用法
 * <p>
 * Created by JessYan on 9/4/16 12:56
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * ================================================
 */
public class SearchItemHolder extends BaseHolder<PatientInfo> {
    @BindView(R.id.search_item_layout)
    ConstraintLayout mLayout;

    @BindView(R.id.txvi_searchitemlayout_department)
    TextView txviDepartment;
    @BindView(R.id.txvi_searchitemlayout_visitors)
    TextView txviVisitors;
    @BindView(R.id.txvi_searchitemlayout_campus)
    TextView txviCampus;

    @BindView(R.id.txvi_searchitemlayout_time)
    TextView txviTime;

    public SearchItemHolder(View itemView) {
        super(itemView);

    }

    @Override
    public void setData(@NonNull PatientInfo info, int position) {

        txviDepartment.setText(CommonUtils.isEmptyReturnStr(info.getDeptName()));
        txviVisitors.setText(CommonUtils.isEmptyReturnStr(info.getName()));
        txviCampus.setText(CommonUtils.isEmptyReturnStr(info.getSecName()));
        txviTime.setText(CommonUtils.isEmptyReturnStr(info.getCreatedAt()));
    }

    /**
     * 动态设置Margin
     */
    private void setLayoutMargin(boolean isSet) {
        ConstraintLayout.LayoutParams layoutParam = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.WRAP_CONTENT);
        if (isSet)
            layoutParam.setMargins(0, ConvertUtils.dp2px(10), 0, 0);
        else
            layoutParam.setMargins(0, 0, 0, 0);

        mLayout.setLayoutParams(layoutParam);
    }

    /**
     * 在 Activity 的 onDestroy 中使用 {@link DefaultAdapter#releaseAllHolder(RecyclerView)} 方法 (super.onDestroy() 之前)
     * {@link BaseHolder#onRelease()} 才会被调用, 可以在此方法中释放一些资源
     */
    @Override
    protected void onRelease() {
        this.mLayout = null;

        this.txviDepartment = null;
        this.txviVisitors = null;
        this.txviCampus = null;
        this.txviTime = null;
    }
}
